#pragma once

#include "Xml.h"

struct NetPeer
{
	std::string ip;
	std::string port;
	std::string aet;
	std::string peerName;
};
struct QrConfig
{
	std::string recvPort;
	std::string recvAET;
	std::vector<NetPeer> peerList;
};

class CPacsSetUI : public WindowImplBase, public IListCallbackUI
{
public:
	CPacsSetUI(HWND hParent = NULL, HWND hOwner = NULL, BOOL bSelfDel = FALSE);
	~CPacsSetUI();

	static BOOL ReadConfig(QrConfig* pCfg);
	QrConfig& GetQrConfig() { return m_cfg; }

public:
	LPCTSTR GetWindowClassName() const;

	virtual void OnFinalMessage(HWND hWnd);

	virtual void InitWindow();

	//virtual LRESULT ResponseDefaultKeyEvent(WPARAM wParam);

	virtual DString GetSkinFile();

	virtual DString GetSkinFolder();

	virtual CControlUI* CreateControl(LPCTSTR pstrClass);

	virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);

	virtual LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

	virtual LPCTSTR GetItemText(CControlUI* pControl, int iIndex, int iSubItem);

private:

	BOOL m_bSelfDel;
	HWND m_hOwner;
	CXml m_xml;
	QrConfig m_cfg;
	DString m_RecvPort;
	DString m_RecvAET;
	DString m_PeerIp;
	DString m_PeerAET;
	DString m_PeerPort;
	DString m_PeerDesc;

	CEditUI* m_edtLPort;
	CEditUI* m_edtLAet;
	CEditUI* m_edtRIp;
	CEditUI* m_edtRPort;
	CEditUI* m_edtRAet;
	CEditUI* m_edtRDesc;
	CListUI* m_lstServer;

	int m_nCurSel;

	BOOL ReadConfig();
	BOOL SaveConfig();
	void RefreshList();
	void UpdateData(BOOL bGet=TRUE);

protected:
	void Notify(TNotifyUI& msg);
	void OnPrepare(TNotifyUI& msg);
	void OnExit(TNotifyUI& msg);

	void OnBtnAdd();
	void OnBtnMod();
	void OnBtnDel();
	void OnBtnVerify();
	void OnBtnSave();
	void OnBtnExit();
};

